package com.obas.view {

   import com.obas.component.tree.treeclass.Node;
   import com.obas.model.business.Explorer;

   import mx.collections.ArrayCollection;
   import mx.collections.ICollectionView;
   import mx.controls.treeClasses.DefaultDataDescriptor;

   public class NaviTreeDataDesc extends DefaultDataDescriptor {
      public function NaviTreeDataDesc() {
         super();
      }

      override public function getChildren(node:Object, model:Object = null):ICollectionView {
         if (node is Node) {
            var treeNode:Node = node as Node;
            if (treeNode.children && treeNode.children.length > 0) {
               var ret:ArrayCollection = new ArrayCollection();
               for each (var childNode:* in treeNode.children) {
                  if (childNode is Node && childNode.entity is Explorer && !Explorer(childNode.entity).display) {
                     for each (var gchildNode:Node in childNode.children) {
                        ret.addItem(gchildNode);
                     }
                  }
                  else {
                     ret.addItem(childNode);
                  }
               }
               return ret;
            }
            return node.children;
         }
         else {
            return null;
         }
      }

      override public function isBranch(node:Object, model:Object = null):Boolean {
         if (node is Node) {
            return node.children != null;
         }
         else {
            return false;
         }
      }
   }
}